#pragma once
#ifndef OBR_MIPMAP_H
#define OBR_MIPMAP_H

#include "SharedDS/MipmapDS.h"
#include "Texture.h"
#include "common.h"
#include "helpers/Helpers.h"

namespace OBR
{
/**
 * @brief a LOD structure of 2d textures
 *
 * @tparam DataType
 */
template <typename DataType> class Mipmap
{
public:
    Texture<DataType, 2> *levels = nullptr;
    uint num_levels;
    bool initialized = false;

private:
    CudaBuffer d_mipmap_levels;

public:
    Mipmap();
    Mipmap(const Texture<DataType, 2> &src);
    ~Mipmap();

    /**
     * @brief get DeviceMipmap object with proper device memory layout
     *
     * @return DeviceMipmap
     */
    DeviceMipmap<DataType> getDeviceMipmap();

    /**
     * @brief create this mipmap from a given texture
     *
     * @param src
     */
    void createFromTexture(const Texture<DataType, 2> &src);

private:
    void uploadLevelData();
};

typedef Mipmap<Spectrum> ColorMipmap;
typedef Mipmap<float> FloatMipmap;

} // namespace OBR

#endif
